package com.surfilter.msmp.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Description：日期类函数工具类
 * Author；JinHuatao
 * Date: 2019/6/14 18:26
 */
public class DateUtil {

    public static Map<String, String> getLastHour(int passHour) {
        Map<String, String> rsMap = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        Date endDate = calendar.getTime();
        calendar.roll(Calendar.HOUR, passHour);
        Date startDate = calendar.getTime();

        String startTime = sdf.format(startDate);
        String endTime = sdf.format(endDate);

        rsMap.put("st", startTime);
        rsMap.put("et", endTime);
        return rsMap;
    }

    public static int getLastMonth(int peroid) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Calendar calendar = Calendar.getInstance();
        calendar.roll(Calendar.MONTH, peroid);
        Date startDate = calendar.getTime();
        String st = sdf.format(startDate);
        return Integer.parseInt(st);
    }

    public static void main(String[] args) {
//        Map<String, String> mp = getLastHour(-2);
//        System.out.println(mp);
        System.out.println(getLastMonth(-3));
    }

}
